<?php
echo "Project-Account mapping start<br/>";
include_once('config.inc.php');

$mappings=file('./INCLUDE.csv');

$link=mysql_connect($hostname,$username,$password); 

$status=mysql_select_db("vtigercrm520");

/**
 * An array with mapping between 
 * vtiger projectID and Kontakt projectID
 */

$k2vtProjects=array(
   4094285 => 5106,
 	1565852 => 13833,
	4750688 => 13834,
	4894811 => 13835,
	5621431 => 13836, 	
 	5637352 => 13837,
 	7098321 => 13838, 	
 	7607935 => 13839,
 	11581109 => 13840, 	
 	12451039 => 13841,
 	12857929 => 13842, 	
 	13400907 => 13843
 	);

foreach ($mappings as $mappingstring) {
   $currentmap=explode(';',$mappingstring);
   $KontaktPROJECTID=$currentmap[0];
   $KontaktCONTACTID=$currentmap[1];
   echo "Processing Kontakt PROJECT $KontaktPROJECTID and Kontact CONTACT $KontaktCONTACTID <br/>";
	
	$aidquery="SELECT accountid FROM vtiger_accountscf WHERE cf_662 = $KontaktCONTACTID";
	$execaidquery=mysql_query($aidquery, $link);
	if(!$execaidquery) {
			print("Query Error: ".mysql_error()."<br/>");
		}
	while($aidresult=mysql_fetch_assoc($execaidquery)) {
	$currentaid=$aidresult['accountid'];
   }
   
   $insertquery="INSERT INTO vtiger_campaignaccountrel VALUES ('$k2vtProjects[$KontaktPROJECTID]','$currentaid','1')";
   print("Executing query : $insertquery with Kontakt values pid=$KontaktPROJECTID and cid=$KontaktCONTACTID <br/>");
   $execinsertquery=mysql_query($insertquery,$link);
   if(!$execinsertquery) {
			print("Query Error: ".mysql_error()."<br/>");
		}
}

mysql_close($link);
print("<br/>All done.");
?>